const install = (vue, options) => {
	let request = (options) => {
		options = Object.assign({
				baseURL: "http://180.76.120.179:8081",
				url: "",
				data: {},
				method: "",
				header: {},
			},
			options
		);


		//携带请求标识
		if (uni.getStorageSync("token")) {
			options.header.token = uni.getStorageSync("token") || "";
		}
		//拼接最终的请求地址
		options.url = options.baseURL + options.url;


		return new Promise((resolve, reject) => {
			uni.request({
				url: options.url,
				data: options.data,
				method: options.method,
				header: options.header,
				dataType: "json",
				success: (res) => {
					resolve(res.data);
				},
				fail: (err) => {
					reject(err);
				},
			});
		});
	};
	//差异
	request.get = (url, data, options) => {
		options = Object.assign({
				url,
				data,
				method: "GET",
			},
			options
		);
		return request(options);
	};




	//差异
	request.post = (url, data, options) => {
		options = Object.assign({
				url,
				data,
				method: "POST",
			},
			options
		);
		return request(options);
	};




	vue.prototype.$request = request;
};

export default install;
